In [30]:
# Cross-notebook include shim
with open("nbinclude.ipynb") as nbinclude_f: # don't rename nbinclude_f
    import IPython.nbformat.current
    get_ipython().run_cell(IPython.nbformat.current.read(nbinclude_f, 'json').worksheets[0].cells[0].input)

Motor


In [1]:
class Motor(object):
    def __init__(self):
        self._throttle = 0

    @property
    def throttle(self):
        return self._throttle

    @throttle.setter
    def throttle(self, value):
        self._throttle = value

In [2]:
m = Motor()

In [3]:
m.throttle


Out[3]:
0

In [4]:
m.throttle = 30

In [5]:
m.throttle


Out[5]:
30

Line Scan Camera


In [20]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
class LineScanCamera(object):
    def __init__(self):
        self._image = np.zeros(128)

    @property
    def image(self):
        return self._image

In [15]:
cam = LineScanCamera()

In [16]:
plt.plot(cam.image)


Out[16]:
[<matplotlib.lines.Line2D at 0x7f024ec77d10>]

Servo


In [21]:
class Servo(object):
    def __init__(self):
        self._position = 0
        self._velocity = 0

    @property
    def position(self):
        return self._position

    @position.setter
    def position(self, value):
        self._position = value
        
    @property
    def velocity(self):
        return self._velocity

    @velocity.setter
    def velocity(self, value):
        self._velocity = value

In [22]:
s = Servo()

In [23]:
s.position


Out[23]:
0

In [24]:
s.position = 180

In [25]:
s.position


Out[25]:
180

In [27]:
s.velocity


Out[27]:
0

In [28]:
s.velocity = 3

In [29]:
s.velocity


Out[29]:
3

Light Sensor


In [46]:
class LightSensor(object):
    def __init__(self):
        self._light_value = 0

    @property
    def light_value(self):
        return self._light_value

In [44]:
l = LightSensor()

In [45]:
l.light_value


Out[45]:
0

Flashlight


In [ ]:
class Flashlight(object):
    def __init__(self):
        self._brightness = 0

    @property
    def brightness(self):
        return self._brightness

    @brightness.setter
    def brightness(self, value):
        self._brightness = value